<template>
  <div class="edit-wrapper">
    <el-dialog :title="title" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible">
      <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="method==='view'"
        label-width="80px">
        <el-row>
          <el-col>
            <el-form-item label="车轴类型:" prop="axle">
              <el-input v-model="inputForm.axle.axle" placeholder="请输入车轴类型" readonly :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="车辆类型:" prop="axle">
                <span>{{$dictUtils.getDictLabel("truckType", inputForm.truckType, "")}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="装车费:" prop="loadFee" :rules="[
                  {validator: validator.maxValue, trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.loadFee" placeholder="请输入装车费" v-thousands.loadFee="inputForm"  show-word-limit> <template slot="append">元</template></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-col>
            <el-form-item label="卸车费:" prop="unloadFee" :rules="[
                  {validator: validator.maxValue, trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.unloadFee" v-thousands.unloadFee="inputForm" placeholder="请输入卸车费"  show-word-limit> <template slot="append">元</template></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
        <el-button @click="visible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          ids: '',
          axle: {
              axle:''
          },
          truckType:0,
          loadFee: 0,
          unloadFee: 0
        }
      }
    },
    components: {},
    methods: {
    	handleClose(done) {
			this.$Msg.confirm({
				title:'您确定要关闭吗？',
				content:this.GLOBAL.FORM_CLOSE_TIPS,
				confirmCall:()=>{
					done();
				}
			})
		},
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        this.inputForm.ids = id
        if (method === 'edit') {
          this.title = '修改车轴装卸车费'
        } else if (method === 'edits') {
          this.title = '修改车轴装卸车费'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/truck/truckType/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({
              data
            }) => {
              this.inputForm = this.recover(this.inputForm, data.result)
              this.inputForm.ids = id
              this.loading = false
            })
          } else if (method === 'edits') {
            this.loading = true
            this.$http({
              url: `/truck/truckType/queryByIds?ids=${this.inputForm.ids}`,
              method: 'get'
            }).then(({
              data
            }) => {
              if(data && data.success){
                var axles = ''
                for (var i = 0; i < data.result.length; i++) {
                  axles += data.result[i].axle.axle + ','
                }
                this.inputForm.axle.axle = axles
                this.inputForm.ids = id
                this.loading = false
              } else {
                this.loading = false
                this.visible = false
              }
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
            //批量修改接口不需要传id
          this.inputForm.id = ''
          if (valid) {
            this.loading = true
            this.$http({
              url: `/truck/truckType/modifyFeeList`,
              method: 'post',
              data: this.inputForm
            }).then(({
              data
            }) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.message)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .edit-wrapper{
    ::v-deep.el-dialog{
      .el-form{
        .el-row:first-child{
          .el-input__inner{
            width: 320px;
          }
        }
        .el-row:nth-child(2){
          .el-input__inner{
            width: 294px;
          }
        }
        .el-input-group__append{
          background: transparent;
          border: none;
          padding: 0 0 0 10px;
          font-size: 14px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #999999;
        }
        .more-content{
          display: flex;
          .right-content{
            margin-left: -10px;
          }
          .right-content>div{
            margin-bottom: 20px;
            display: block;
            width: 100%;

            .el-input__inner{
              width: 224px;
            }

          }
        }

      }
    }
  }
</style>
